//
//  HomeDataListViewController.m
//  StormWatch
//
//  Created by 王岩 on 2024/8/31.
//

#import "HomeDataListViewController.h"
#import "HomeStepViewCell.h"
#import "HomeSleepViewCell.h"
#import "SleepTable+CoreDataClass.h"
#import "BaseInfoTable+CoreDataClass.h"
#import "HeartTable+CoreDataClass.h"
#import "OxygenTable+CoreDataClass.h"

@interface HomeDataListViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *introLab;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, assign) RecordType  recordType;

/* <#note#> */
@property (nonatomic, strong) NSMutableArray * dataArr;
@end

@implementation HomeDataListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString * uuid = self.metaInfo[@"uuid"];
    NSArray * list = [FRQBluetoothManager shareManager].curPeripherals;
    for (CBPeripheral * per in list) {
        if ([per.identifier.UUIDString isEqualToString:uuid]) {
            self.peripheral = per;
        }
    }
    self.recordType = [self.metaInfo[@"type"] intValue];
    
    if (self.recordType == RecordType_Step) {
        self.jy_title = SWString(@"Step");
        self.nameLab.text = SWString(@"My step");
        self.introLab.text = SWString(@"Walking long  long long Introduce");
    }else if (self.recordType == RecordType_Heat) {
        self.jy_title = SWString(@"Heat consumption");
        self.nameLab.text = SWString(@"My heat consumption");
        self.introLab.text = SWString(@"Calorie consumption long  long long Introduce");
    }else if (self.recordType == RecordType_Distance) {
        self.jy_title = SWString(@"Motion distance");
        self.nameLab.text = SWString(@"My motion distance");
        self.introLab.text = SWString(@"Exercise distance long long introduce");
    }else if (self.recordType == RecordType_Sleep) {
        self.jy_title = SWString(@"Sleep");
        self.nameLab.text = SWString(@"My sleep");
        self.introLab.text = SWString(@"Sleep long  long long Introduce");
    }else if (self.recordType == RecordType_HeartReat) {
        self.jy_title = SWString(@"Heart rate");
        self.nameLab.text = SWString(@"My heart rate");
        self.introLab.text = SWString(@"heartbeat long  long long Introduce");
    }else if (self.recordType == RecordType_RespiratoryReat) {
        self.jy_title = SWString(@"呼吸率");
        self.nameLab.text = SWString(@"呼吸率");
        self.introLab.text = SWString(@"heartbeat long  long long Introduce");
    }else if (self.recordType == RecordType_BloodOxygen) {
        self.jy_title = SWString(@"Blood oxygen");
        self.nameLab.text = SWString(@"My blood oxygen");
        self.introLab.text = SWString(@"Blood oxygen long  long long Introduce");
    }
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeStepViewCell" bundle:nil] forCellReuseIdentifier:@"HomeStepViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeSleepViewCell" bundle:nil] forCellReuseIdentifier:@"HomeSleepViewCell"];
    [self initDBData];
    if (self.peripheral) {
        [self readData];
    }
   
    //66d88b0f6b 66d8a72f62 66d8b53f5f 66d97e965c 66d9672350 66d9960534
//    004a0038000066da0d5204 66da19fa0166da217a0266 da25b20166da25ee0466da bbb20166dac2f60266dacb de0166dace3604 Do any additional setup after loading the view from its nib.
}

- (void)initDBData {
    NSManagedObjectContext * context = [[DBManager sharedManager] managedObjectContext];

    if (self.recordType == RecordType_Sleep) {
        NSFetchRequest *  request = [[NSFetchRequest alloc] initWithEntityName:@"SleepTable"];
        NSSortDescriptor * sort = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO];
        request.sortDescriptors = @[sort];
        NSPredicate * predicate = [NSPredicate predicateWithFormat:@"deviceUUID = %@",self.peripheral.identifier.UUIDString];
        request.predicate = predicate;
        NSArray<SleepTable *> * result = [context executeFetchRequest:request error:nil];
        
        for (int i = 0; i < result.count; i ++) {
            HomeSleepModel*m = [[HomeSleepModel alloc] init];
            m.lightValueStr = [NSString stringWithFormat:@"%lldH %lldM",result[i].lightData/60,result[i].lightData%60];
            m.deepValueStr = [NSString stringWithFormat:@"%lldH %lldM",result[i].deepData/60,result[i].deepData%60];
            m.dateStr = result[i].date;
            [self.dataArr addObject:m];
        }
    }else if (self.recordType == RecordType_Step  || self.recordType == RecordType_Distance || self.recordType == RecordType_Heat) {
        NSFetchRequest *  request = [[NSFetchRequest alloc] initWithEntityName:@"BaseInfoTable"];
        NSSortDescriptor * sort = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO];
        request.sortDescriptors = @[sort];
        NSPredicate * predicate = [NSPredicate predicateWithFormat:@"deviceUUID = %@",self.peripheral.identifier.UUIDString];
        request.predicate = predicate;
        NSArray<BaseInfoTable *> * result = [context executeFetchRequest:request error:nil];
        for (int i = 0; i < result.count; i ++) {
            HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
            m.dateStr = result[i].date;
            if (self.recordType == RecordType_Step) {
                m.valueStr = [NSString stringWithFormat:@"%@%@",result[i].stepData,SWString(@"step")];
            }else if (self.recordType == RecordType_Heat) {
                m.valueStr = [NSString stringWithFormat:@"%@%@",result[i].caloriesData,@"kCal"];
            }else if (self.recordType == RecordType_Distance ){
                m.valueStr = [NSString stringWithFormat:@"%@%@",result[i].distanceData,@"Km"];
            }
            [self.dataArr addObject:m];
        }
    }else if (self.recordType == RecordType_HeartReat) {
        NSFetchRequest *  request = [[NSFetchRequest alloc] initWithEntityName:@"HeartTable"];
        NSSortDescriptor * sort = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO];
        request.sortDescriptors = @[sort];
        NSPredicate * predicate = [NSPredicate predicateWithFormat:@"deviceUUID = %@",self.peripheral.identifier.UUIDString];
        request.predicate = predicate;
        NSArray<HeartTable *> * result = [context executeFetchRequest:request error:nil];
        for (int i = 0; i < result.count; i ++) {
            HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
            m.dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%d",result[i].date] Format:@"yyyy-MM-dd HH:mm:ss"];
            m.valueStr = [NSString stringWithFormat:@"%@ %@",result[i].heartData,@"BMP"];
            [self.dataArr addObject:m];
        }
    }else if (self.recordType == RecordType_BloodOxygen) {
        NSFetchRequest *  request = [[NSFetchRequest alloc] initWithEntityName:@"OxygenTable"];
        NSSortDescriptor * sort = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO];
        request.sortDescriptors = @[sort];
        NSPredicate * predicate = [NSPredicate predicateWithFormat:@"deviceUUID = %@",self.peripheral.identifier.UUIDString];
        request.predicate = predicate;
        NSArray<OxygenTable *> * result = [context executeFetchRequest:request error:nil];
        for (int i = 0; i < result.count; i ++) {
            HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
            m.dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%d",result[i].date] Format:@"yyyy-MM-dd HH:mm:ss"];
            m.valueStr = [NSString stringWithFormat:@"%@",result[i].oxygenData];
            [self.dataArr addObject:m];
        }
    }
    
    [self.tableView reloadData];
}

- (void)readData {
    
    NSManagedObjectContext * context = [[DBManager sharedManager] managedObjectContext];
    
    if (self.recordType == RecordType_Step  || self.recordType == RecordType_Distance || self.recordType == RecordType_Heat) {
        [WatchCommandTool.sharedInstance readRealTimeDataFromPeripheral:self.peripheral Block:^(BOOL success, unsigned long stepData, unsigned long caloriesData, unsigned long distanceData, unsigned long heartRateData, unsigned long electricData) {
            if (success) {
                HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
                NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
                m.dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%f",interval] Format:@"yyyy-MM-dd"];
                if (self.recordType == RecordType_Step) {
                    m.valueStr = [NSString stringWithFormat:@"%lu%@",stepData,SWString(@"step")];
                }else if (self.recordType == RecordType_Heat) {
                    m.valueStr = [NSString stringWithFormat:@"%.2f%@",caloriesData / 1000.0,@"kCal"];
                }else if (self.recordType == RecordType_Distance ){
                    m.valueStr = [NSString stringWithFormat:@"%.2f%@",distanceData / 1000.0,@"Km"];
                }
               
                BOOL ha = NO;
                for (HomeStepItemModel * model in self.dataArr) {
                    if ([model.dateStr isEqualToString:m.dateStr]) {
                        ha = YES;
                        model.valueStr = m.valueStr;
                        break;
                    }
                }
                if (!ha) {
                    [self.dataArr insertObject:m atIndex:0];
                }
                [self.tableView reloadData];
                
                ///  更新数据库
                NSFetchRequest * request = [NSFetchRequest fetchRequestWithEntityName:@"BaseInfoTable"];
                NSPredicate * predicate = [NSPredicate predicateWithFormat:@"date == %@ && deviceUUID = %@",m.dateStr, self.peripheral.identifier.UUIDString];
                request.predicate = predicate;
                NSArray<BaseInfoTable *> *result = [context executeFetchRequest:request error:nil];
                if (result.count > 0) {
                    result[0].stepData = [NSString stringWithFormat:@"%lu",stepData];
                    result[0].caloriesData = [NSString stringWithFormat:@"%lu",caloriesData];
                    result[0].distanceData = [NSString stringWithFormat:@"%lu",distanceData];
                    result[0].heartRateData = [NSString stringWithFormat:@"%lu",heartRateData];
                }else {
                    BaseInfoTable * st = [NSEntityDescription insertNewObjectForEntityForName:@"BaseInfoTable" inManagedObjectContext:context];
                    st.stepData = [NSString stringWithFormat:@"%lu",stepData];
                    st.caloriesData = [NSString stringWithFormat:@"%lu",caloriesData];
                    st.distanceData = [NSString stringWithFormat:@"%lu",distanceData];
                    st.heartRateData = [NSString stringWithFormat:@"%lu",heartRateData];
                    st.date = m.dateStr;
                    st.deviceUUID = self.peripheral.identifier.UUIDString;
                }
                [[DBManager sharedManager] saveContext];
                
            }
        }];
    }else if (self.recordType == RecordType_Sleep) {
        [[WatchCommandTool sharedInstance] readSleepData:^(BOOL success, unsigned long deepSleepData, unsigned long lightSleepData, unsigned long dateData) {
            HomeSleepModel*m = [[HomeSleepModel alloc] init];
            
            NSLog(@"浅睡眠时间（分）：%lu",lightSleepData);
            m.lightValueStr = [NSString stringWithFormat:@"%luH %luM",lightSleepData/60,lightSleepData%60];

            NSLog(@"深睡眠时间（分）%lu",deepSleepData);
            m.deepValueStr = [NSString stringWithFormat:@"%luH %luM",deepSleepData/60,deepSleepData%60];

            NSString * dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%lu",dateData] Format:@"yyyy-MM-dd"];
            NSLog(@"时间：%@",dateStr);
            m.dateStr = dateStr;
            BOOL ha = NO;
            for (HomeSleepModel * model in self.dataArr) {
                if ([model.dateStr isEqualToString:m.dateStr]) {
                    ha = YES;
                    model.deepValueStr = m.deepValueStr;
                    model.lightValueStr = m.lightValueStr;
                    break;
                }
            }
            if (!ha) {
                [self.dataArr insertObject:m atIndex:0];
            }
            [self.tableView reloadData];
            
            ///  更新数据库
            NSFetchRequest * request = [NSFetchRequest fetchRequestWithEntityName:@"SleepTable"];
            NSPredicate * predicate = [NSPredicate predicateWithFormat:@"date = %@ && deviceUUID = %@",m.dateStr, self.peripheral.identifier.UUIDString];
            request.predicate = predicate;
            NSArray<SleepTable *> *result = [context executeFetchRequest:request error:nil];
            if (result.count > 0) {
                result[0].date = dateStr;
                result[0].deepData = (int)deepSleepData;
                result[0].lightData = (int)lightSleepData;
            }else {
                SleepTable * st = [NSEntityDescription insertNewObjectForEntityForName:@"SleepTable" inManagedObjectContext:context];
                st.date = dateStr;
                st.deepData = (int)deepSleepData;
                st.lightData = (int)lightSleepData;
                st.deviceUUID = self.peripheral.identifier.UUIDString;
            }
            [[DBManager sharedManager] saveContext];
          
        } ToPeripheral:self.peripheral];
        
    }else if (self.recordType == RecordType_HeartReat) {
       
        [[WatchCommandTool sharedInstance] readStormCommand:Command_HeartRateHistory ToPeripheral:self.peripheral  reBack:^(NSString * _Nonnull backData) {
            if (backData.length > 26) {
                NSString * valueStr = [backData substringFromIndex:26];
                
                for (int i = 0 ; i < valueStr.length / 10; i ++) {
                    NSString * itemStr = [valueStr substringWithRange:NSMakeRange(i * 10, 10)];
                    NSString * dateD = [itemStr substringToIndex:8];
                    NSString * rateD = [itemStr substringFromIndex:8];
                    unsigned long dateValue = strtoll([[NSString stringWithFormat:@"0x%@",dateD] UTF8String], 0, 16);
                    NSString * dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%lu",dateValue] Format:@"yyyy-MM-dd HH:mm:ss"];
                    unsigned long rateValue = strtoll([[NSString stringWithFormat:@"0x%@",rateD] UTF8String], 0, 16);
                    HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
                    m.dateStr = dateStr;
                    m.valueStr = [NSString stringWithFormat:@"%lu BMP",rateValue];
                    
                    BOOL ha = NO;
                    for (HomeStepItemModel * model in self.dataArr) {
                        if ([model.dateStr isEqualToString:m.dateStr]) {
                            ha = YES;
                            model.valueStr = m.valueStr;
                            break;
                        }
                    }
                    if (!ha) {
                        [self.dataArr insertObject:m atIndex:0];
                    }
                    
                    ///  更新数据库
                    NSFetchRequest * request = [NSFetchRequest fetchRequestWithEntityName:@"HeartTable"];
                    NSPredicate * predicate = [NSPredicate predicateWithFormat:@"date = %lu && deviceUUID = %@",dateValue, self.peripheral.identifier.UUIDString];
                    request.predicate = predicate;
                    NSArray<HeartTable *> *result = [context executeFetchRequest:request error:nil];
                    if (result.count > 0) {
                        result[0].heartData = [NSString stringWithFormat:@"%lu",rateValue];
                        result[0].deviceUUID = self.peripheral.identifier.UUIDString;
                        result[0].date = (int32_t)dateValue;
                    }else {
                        HeartTable * st = [NSEntityDescription insertNewObjectForEntityForName:@"HeartTable" inManagedObjectContext:context];
                        st.heartData = [NSString stringWithFormat:@"%lu",rateValue];
                        st.date = (int32_t)dateValue;
                        st.deviceUUID = self.peripheral.identifier.UUIDString;
                    }
                    [[DBManager sharedManager] saveContext];
                    
                }
            }
            [self.tableView reloadData];
        } ];
    }else if (self.recordType == RecordType_RespiratoryReat) {
       
        [[WatchCommandTool sharedInstance] readStormCommand:Command_HeartRateHistory ToPeripheral:self.peripheral  reBack:^(NSString * _Nonnull backData) {
            if (backData.length > 26) {
                NSString * valueStr = [backData substringFromIndex:26];
                
                for (int i = 0 ; i < valueStr.length / 10; i ++) {
                    NSString * itemStr = [valueStr substringWithRange:NSMakeRange(i * 10, 10)];
                    NSString * dateD = [itemStr substringToIndex:8];
                    NSString * rateD = [itemStr substringFromIndex:8];
                    unsigned long dateValue = strtoll([[NSString stringWithFormat:@"0x%@",dateD] UTF8String], 0, 16);
                    NSString * dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%lu",dateValue] Format:@"yyyy-MM-dd HH:mm:ss"];
                    unsigned long rateValue = strtoll([[NSString stringWithFormat:@"0x%@",rateD] UTF8String], 0, 16);
                    HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
                    m.dateStr = dateStr;
                    m.valueStr = [NSString stringWithFormat:@"%lu BMP",rateValue / 4];
                    
                    BOOL ha = NO;
                    for (HomeStepItemModel * model in self.dataArr) {
                        if ([model.dateStr isEqualToString:m.dateStr]) {
                            ha = YES;
                            model.valueStr = m.valueStr;
                            break;
                        }
                    }
                    if (!ha) {
                        [self.dataArr insertObject:m atIndex:0];
                    }
                    
                    ///  更新数据库
                    NSFetchRequest * request = [NSFetchRequest fetchRequestWithEntityName:@"HeartTable"];
                    NSPredicate * predicate = [NSPredicate predicateWithFormat:@"date = %lu && deviceUUID = %@",dateValue, self.peripheral.identifier.UUIDString];
                    request.predicate = predicate;
                    NSArray<HeartTable *> *result = [context executeFetchRequest:request error:nil];
                    if (result.count > 0) {
                        result[0].heartData = [NSString stringWithFormat:@"%lu",rateValue / 4];
                        result[0].deviceUUID = self.peripheral.identifier.UUIDString;
                        result[0].date = (int32_t)dateValue;
                    }else {
                        HeartTable * st = [NSEntityDescription insertNewObjectForEntityForName:@"HeartTable" inManagedObjectContext:context];
                        st.heartData = [NSString stringWithFormat:@"%lu",rateValue / 4];
                        st.date = (int32_t)dateValue;
                        st.deviceUUID = self.peripheral.identifier.UUIDString;
                    }
                    [[DBManager sharedManager] saveContext];
                    
                }
            }
            [self.tableView reloadData];
        } ];
    }else if (self.recordType == RecordType_BloodOxygen) {
       
        [[WatchCommandTool sharedInstance] readStormCommand:Command_BloodOxygenHistory ToPeripheral:self.peripheral reBack:^(NSString * _Nonnull backData) {
            if (backData.length > 26) {
                NSString * valueStr = [backData substringFromIndex:26];
                
                for (int i = 0 ; i < valueStr.length / 10; i ++) {
                    NSString * itemStr = [valueStr substringWithRange:NSMakeRange(i * 10, 10)];
                    NSString * dateD = [itemStr substringToIndex:8];
                    NSString * rateD = [itemStr substringFromIndex:8];
                    unsigned long dateValue = strtoll([[NSString stringWithFormat:@"0x%@",dateD] UTF8String], 0, 16);
                    NSString * dateStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%lu",dateValue] Format:@"yyyy-MM-dd HH:mm:ss"];
                    unsigned long rateValue = strtoll([[NSString stringWithFormat:@"0x%@",rateD] UTF8String], 0, 16);
                    HomeStepItemModel * m = [[HomeStepItemModel alloc] init];
                    m.dateStr = dateStr;
                    m.valueStr = [NSString stringWithFormat:@"%lu",rateValue];
                    
                    BOOL ha = NO;
                    for (HomeStepItemModel * model in self.dataArr) {
                        if ([model.dateStr isEqualToString:m.dateStr]) {
                            ha = YES;
                            model.valueStr = m.valueStr;
                            break;
                        }
                    }
                    if (!ha) {
                        [self.dataArr insertObject:m atIndex:0];
                    }
                    
                    ///  更新数据库
                    NSFetchRequest * request = [NSFetchRequest fetchRequestWithEntityName:@"OxygenTable"];
                    NSPredicate * predicate = [NSPredicate predicateWithFormat:@"date = %lu && deviceUUID = %@",dateValue, self.peripheral.identifier.UUIDString];
                    request.predicate = predicate;
                    NSArray<OxygenTable *> *result = [context executeFetchRequest:request error:nil];
                    if (result.count > 0) {
                        result[0].oxygenData = [NSString stringWithFormat:@"%lu",rateValue];
                        result[0].deviceUUID = self.peripheral.identifier.UUIDString;
                        result[0].date = (int32_t)dateValue;
                    }else {
                        OxygenTable * st = [NSEntityDescription insertNewObjectForEntityForName:@"OxygenTable" inManagedObjectContext:context];
                        st.oxygenData = [NSString stringWithFormat:@"%lu",rateValue];
                        st.date = (int32_t)dateValue;
                        st.deviceUUID = self.peripheral.identifier.UUIDString;
                    }
                    [[DBManager sharedManager] saveContext];
                    
                }
            }
            [self.tableView reloadData];
        }] ;
    }else if (self.recordType == RecordType_BloodPressure) {
        [WatchCommandTool.sharedInstance readBloodPressureData:^(BOOL success, NSArray * _Nonnull list) {
            for (int i = 0 ; i < list.count; i ++) {
                HomeSleepModel * m = [[HomeSleepModel alloc] init];
                m.dateStr = list[i][@"d"];
                m.lightValueStr = list[i][@"r"];
                m.deepValueStr = list[i][@"s"];
                [self.dataArr addObject:m];
            }
            [self.tableView reloadData];
        } ToPeripheral:self.peripheral];
    }
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.recordType == RecordType_Sleep || self.recordType == RecordType_BloodPressure) {
        HomeSleepViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeSleepViewCell" forIndexPath:indexPath];
        cell.model = self.dataArr[indexPath.row];
        if (self.recordType == RecordType_Sleep) {
            cell.deepLab.text = SWString(@"Deep sleep");
            cell.lightLab.text = SWString(@"Light sleep");
        }else {
            cell.deepLab.text = SWString(@"收缩压");
            cell.lightLab.text = SWString(@"舒张压");
        }
        return cell;
    }else {
        HomeStepViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeStepViewCell" forIndexPath:indexPath];
        
        
        if (self.recordType == RecordType_Step) {
           
            
        }else if (self.recordType == RecordType_Heat) {
           
            
        }else if (self.recordType == RecordType_Distance) {
          
            
        }else if (self.recordType == RecordType_HeartReat) {
           
            
        }
        
        cell.model = self.dataArr[indexPath.row];
       
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.recordType == RecordType_Step) {
        
        
    }else if (self.recordType == RecordType_Heat) {
        
        
    }else if (self.recordType == RecordType_Distance) {
        
        
    }else if (self.recordType == RecordType_Sleep || self.recordType == RecordType_BloodPressure) {
        return 130;
        
    }else if (self.recordType == RecordType_HeartReat) {
        
        
    }
    return 48;
}


- (NSMutableArray *)dataArr {
    if (!_dataArr ) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return _dataArr;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
